﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Qs.App;      
using Qs.Comm;
using Qs.Repository.Base;
using Qs.Repository.Request;
using Qs.Repository.Response;

namespace Qs.WebApi.Controllers
{
    /// <summary>
    /// 店铺表 
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StoreController : ControllerBase
    {
        private readonly AppStore _app;
        
        /// <summary>
        /// /构造函数
        /// </summary>
        public StoreController(AppStore app) 
        {
            _app = app;
        }
        
        /// <summary>
        /// 列表查询(分页)
        /// </summary>
        [HttpGet]
        public TableData Load([FromQuery]ReqQuStore req)
        {
            return _app.Load(req);
        }
        
        /// <summary>
        /// 列表查询(不分页,page,limit不需要传)
        /// </summary>
        [HttpGet]
        public Response<List<ResStore>> ListByWhere([FromQuery]ReqQuStore req)
        {
            Response<List<ResStore>> res = new Response<List<ResStore>>();
            res.Result = _app.ListByWhere(req);
            return res;
        }
        /// <summary>
        /// 获取详情
        /// </summary>
        [HttpGet]
        [AllowAnonymous]
        public Response<ResStore> GetCurrentStore()
        {
            var result = new Response<ResStore>();
            result.Result = _app.ListByWhere(new ReqQuStore()).FirstOrDefault();
            return result;
        }
        /// <summary>
        /// 获取详情
        /// </summary>
        [HttpGet]
        public Response<ResStore> GetDetail(string id)
        {
            var result = new Response<ResStore>();
            result.Result = _app.GetDetail(id);
            return result;
        }
        /// <summary>
        /// 新增商城
        /// </summary>
        [HttpPost]
        public Response AddStore([FromBody] ReqAuStore req)
        {
            var result = new Response();
            _app.AddStore(req);
            return result;
        }

        /// <summary>
        ///  修改商城(平台管理员)
        /// </summary>
        [HttpPost]
        public Response UpdateStoreInfo([FromBody] ReqUpdateStoreInfo req)
        {
            var result = new Response();
            _app.UpdateStoreInfo(req);
            return result;
        }


        /// <summary>
        /// 修改商城(店铺自己)
        /// </summary>
        [HttpPost]
        public Response UpdateStore([FromBody] ReqUpdateStore req)
        {
            var result = new Response();
            _app.UpdateStore(req);
            return result;
        }
        /// <summary>
        /// 批量删除
        /// </summary>
        [HttpPost]
        public Response Delete([FromBody]string[] ids)
        {
            var result = new Response();
            _app.Delete(ids);
            return result;
        }

     
    }
}
